package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.query.CouponQuery;
import com.tianji.promotion.service.ICouponScopeService;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author ltd
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/coupons")
@Api(tags = "优惠卷相关接口")
@RequiredArgsConstructor
public class CouponController {
     private final ICouponService couponService;

    @PostMapping
    @ApiOperation("新增优惠卷")
    public void addPromotion(@RequestBody @Valid CouponFormDTO couponFormDTO){
        couponService.addPromotion(couponFormDTO);

    }

    @GetMapping("page")
    @ApiOperation("分页查询优惠卷")
    public PageDTO<CouponPageVO> queryCouponPage(CouponQuery couponQuery){

        return couponService.queryCouponPage(couponQuery);
    }
    @PutMapping("/{id}/issue")
    @ApiOperation("发放优惠卷")
    public void vouchersAreIssued(@RequestBody @Valid CouponIssueFormDTO couponIssueFormDTO){
        couponService.vouchersAreIssued(couponIssueFormDTO);

    }

    @GetMapping("list")
    @ApiOperation("查询发放中的优惠卷")
    public List<CouponVO> queryCouponsList(){
      return   couponService.queryCouponsList();


    }

}
